const Token = require('../../domain/auth/token')
const Usecase = require('../../shared/usecase/Usecase')
const R = require('ramda')
class GetUserInfo extends Usecase {
  constructor({ userRepo, config }) {
    super()
    this.userRepo = userRepo
    this.config = config
  }

  async execute(tokenStr) {
    const token = Token.createFromToken(tokenStr, this.config.get('jwt'))
    token.verify()
    const data = await this.userRepo.findById(token.userId)

    return R.omit(
      [
        'password',
        'salt',
        'createdBy',
        'deletedBy',
        'updatedBy',
        'createdAt',
        'deletedAt',
        'updatedAt',
      ],
      data
    )
  }
}

module.exports = GetUserInfo
